﻿@using System.Collections.ObjectModel
@inject DialogService DialogService
@inject CustomerService CustomerService

<RadzenStack Style="display:flex; margin: 10px 0px 10px 0px;" Orientation="Orientation.Horizontal" JustifyContent="JustifyContent.Start">
    <RadzenDatePicker @bind-Value=@startDatetime DateFormat="yyyy-MM-dd" Name="RadzenDatePickerBindValue" ShowCalendarWeek />
    <RadzenDatePicker @bind-Value=@endDatetime DateFormat="yyyy-/MM-dd" Name="RadzenDatePickerBindValue" ShowCalendarWeek />
    <RadzenButton Text="查询" Icon="refresh" Click=@(args => Search()) ButtonStyle="ButtonStyle.Primary"/>
</RadzenStack>
<RadzenDataGrid EmptyText="暂无数据" TItem="CustomerPayLog" Data="@logs" GridLines="Radzen.DataGridGridLines.Default" AllowPaging="true" AllowSorting="true">
    <Columns>
        <RadzenDataGridColumn Property="Id" Title="序号" Width="100px" TextAlign="TextAlign.Center" />
        <RadzenDataGridColumn Property="CreatedTime" Title="收款日期" />
        <RadzenDataGridColumn Property="OldAmount" Title="原账目（元）" />
        <RadzenDataGridColumn Property="ChangeAmount" Title="收款金额（元）" />
        <RadzenDataGridColumn Property="DiscountAmount" Title="优惠金额（元）" />
        <RadzenDataGridColumn Property="NewAmount" Title="收款后账目（元）" />
        <RadzenDataGridColumn Property="Remark" Title="备注" />
    </Columns>
</RadzenDataGrid>

@code {
    [Parameter] 
    public Customer? PCustomer { get; set; }

    DateTime startDatetime { get; set; } = DateTime.Now;
    DateTime endDatetime { get; set; } = DateTime.Now;
    string keyword = string.Empty;
    ObservableCollection<CustomerPayLog> logs = default!;

    async Task Search()
    {
        await Task.Run(() =>
        {
            var input = new BaseInput()
            {
                sdate = startDatetime,
                edate = endDatetime,
                customerid = PCustomer!.Id, 
            };

            var list = CustomerService.SearchCustomerPayLog(input);
            logs = new ObservableCollection<CustomerPayLog>(list);
        });
    }

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
        await Search();
    }

}



